<!DOCTYPE html>
<html>
<head>
    {include file="public/header" /}
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <form class="layui-form layui-form-pane" action="" id="formInfo">
            <!--<fieldset class="table-search-fieldset">-->
                <!--<legend>筛选信息</legend>-->
                <div style="margin: 10px 10px 10px 10px">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">类型</label>
                            <div class="layui-input-inline" style="width: 100px;">
                                <select name="type" lay-filter="selectedInfo">
                                    <option value=""></option>
                                    <option value="1">出售</option>
                                    <option value="2">购进</option>
                                </select>
                            </div>
                        </div>
                        <!--<div class="layui-inline">-->
                            <!--<button type="submit" class="layui-btn layui-btn-primary" lay-submit-->
                                    <!--lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索-->
                            <!--</button>-->
                        <!--</div>-->
                    </div>

                </div>
            <!--</fieldset>-->
        </form>
        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
        <script type="text/html" id="currentTableBar">
            <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="detailInfo">查看详情</a>
        </script>
    </div>
</div>
{include file="public/footer" /}
<!--类型-->
<script type="text/html" id="typeTpl">
    {{#  if(d.type === 1){ }}
    <span>出售</span>
    {{#  } else { }}
    <span>购进</span>
    {{#  } }}
</script>

<script>
    layui.use(['form', 'table', 'laydate'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table,
            laydate = layui.laydate;
        /*交易记录*/
        table.render({
            elem: '#currentTableId',
            url: '/admin/Member/tradLog',
            method: 'post',
            where: {memberCode: "{$memberCode}"},
            parseData: function (res) { //res 即为原始返回的数据
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.msg, //解析提示文本
                    "count": res.data.total, //解析数据长度
                    "data": res.data.data, //解析数据列表
                };
            },
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            cols: [[
                {
                    field: 'imgurl', title: '缩略图', sort: true, align: 'center',
                    templet: function (d) {
                        return '<div onclick="showImg(this)" ><img src="/upload/' + d.imgurl + '" ' + 'alt="" width="50px" height="50px"></div>';
                    }
                },
                {field: 'title', title: '名称', sort: true, align: 'center'},
                {field: 'buy_time', title: '收购日期', sort: true, align: 'center'},
                {field: 'sell_time', title: '出售日期', sort: true, align: 'center'},
                {field: 'type', title: '类型', sort: true, templet: '#typeTpl', align: 'center'},
                {title: '操作', toolbar: '#currentTableBar'}
            ]],
            limits: [10, 15, 20, 25, 30, 50, 100],
            limit: 10,
            page: true,
            skin: 'line,row',
            done: function (res, curr, count) {

            }
        });

        form.on('submit(data-search-btn)', function (data) {
            submitInfo();
        });
        form.on('select(selectedInfo)', function (data) {
            submitInfo();
            return false;
        });

        function submitInfo() {
            var d = {};
            var t = $('#formInfo [name]').serializeArray();
            $.each(t, function () {
                d[this.name] = this.value;
            });
            var result = JSON.stringify(d);
            //执行搜索重载
            table.reload('currentTableId', {
                page: {
                    curr: 1
                }
                , where: {
                    searchParams: result
                }
            }, 'data');
            return false;
        }
        /*查看详情*/
        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event === 'detailInfo') {
                var index = layer.open({
                    title: '查看详情',
                    type: 2,
                    shade: 0.5,
                    maxmin: true,
                    shadeClose: true,
                    area: ['100%', '100%'],
                    content: '/admin/Member/tradLog?action=detail&id=' + data.id+'&mark='+data.type,
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
                return false;
            }
        });

    });

    /*查看大图*/
    function showImg(t) {
        var t = $(t).find("img");
        //页面层
        layer.open({
            type: 1,
            title: '区域图片',
            skin: 'layui-layer-rim', //加上边框
            area: ['600px', '600px'], //宽高 t.width() t.height()
            shadeClose: true, //开启遮罩关闭
            end: function (index, layero) {
                return false;
            },
            content: '<div style="text-align:center"><img src="' + $(t).attr('src') + '" width=\'500px\' style=\'margin-top: 25px;margin-left: 25px\'/></div>'
        });
    }
</script>

</body>
</html>